package lily.phs.object;

import lily.phs.database.Constants;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;


public class MedicateRecord implements Constants{
	
	private Context mContext;
	
	private int mere_profileid=-1;
	private int mere_testid=-1;
	private int mere_id=-1;
	private String mere_name="";
	private String mere_usage="";
	private String mere_dosage="";
	private String mere_time="";
	private int mere_obedience=-1;
	
	public MedicateRecord(Context context){
		this.mContext = context;
	}

	public int getMere_profileid() {
		return mere_profileid;
	}

	public void setMere_profileid(int mere_profileid) {
		this.mere_profileid = mere_profileid;
	}

	public int getMere_testid() {
		return mere_testid;
	}

	public void setMere_testid(int mere_testid) {
		this.mere_testid = mere_testid;
	}

	public int getMere_id() {
		return mere_id;
	}

	public void setMere_id(int mere_id) {
		this.mere_id = mere_id;
	}

	public String getMere_name() {
		return mere_name;
	}

	public void setMere_name(String mere_name) {
		this.mere_name = mere_name;
	}

	public String getMere_usage() {
		return mere_usage;
	}

	public void setMere_usage(String mere_usage) {
		this.mere_usage = mere_usage;
	}

	public String getMere_dosage() {
		return mere_dosage;
	}

	public void setMere_dosage(String mere_dosage) {
		this.mere_dosage = mere_dosage;
	}

	public String getMere_time() {
		return mere_time;
	}

	public void setMere_time(String mere_time) {
		this.mere_time = mere_time;
	}

	public int getMere_obedience() {
		return mere_obedience;
	}

	public void setMere_obedience(int mere_obedience) {
		this.mere_obedience = mere_obedience;
	}

	public void insertMedicateRecord(){
//		int result = -1;
		ContentValues value = new ContentValues();
		value.put(MERE_COLUMN1, this.getMere_profileid());
		value.put(MERE_COLUMN7, this.getMere_testid());
		value.put(MERE_COLUMN8, this.getMere_id());
		value.put(MERE_COLUMN2, this.getMere_name());
		value.put(MERE_COLUMN3, this.getMere_usage());
		value.put(MERE_COLUMN4, this.getMere_dosage());
		value.put(MERE_COLUMN5, this.getMere_time());
		value.put(MERE_COLUMN6, this.getMere_obedience());
		
		mContext.getContentResolver().insert(CONTENT_URI_TB8, value);
//		return result;
		
	}
	
	/**
	 * 检出吃药信息，并实例化对象
	 * @param profileId 档案编号
	 * @param testId 体检表编号
	 * @param _Id 药品使用情况编号
	 */
	public void selectMedicateRecord(int profileId,int testId,int _Id){
		String where = MERE_COLUMN8 + "=" + _Id + " and "+MERE_COLUMN1 + "=" + profileId + " and "+MERE_COLUMN7 + "=" + testId + "";
		Cursor cursor = mContext.getContentResolver().query(CONTENT_URI_TB8, null, where, null, null);
		if(cursor.moveToNext()){
		this.mere_profileid = cursor.getInt(cursor.getColumnIndex(MERE_COLUMN1));
		this.mere_testid = cursor.getInt(cursor.getColumnIndex(MERE_COLUMN7));
		this.mere_id = cursor.getInt(cursor.getColumnIndex(MERE_COLUMN8));
		this.mere_name = cursor.getString(cursor.getColumnIndex(MERE_COLUMN2));
		this.mere_usage = cursor.getString(cursor.getColumnIndex(MERE_COLUMN3));
		this.mere_dosage = cursor.getString(cursor.getColumnIndex(MERE_COLUMN4));
		this.mere_time = cursor.getString(cursor.getColumnIndex(MERE_COLUMN5));
		this.mere_obedience = cursor.getInt(cursor.getColumnIndex(MERE_COLUMN6));
		}
		cursor.close();
	}
	
	/**
	 * 更新吃药信息，并实例化对象
	 * @param profileId 档案编号
	 * @param testId 体检表编号
	 * @param _Id 药品使用情况编号
	 */
	public void updateMedicateRecord(int profileId,int testId,int _Id){
		ContentValues value = new ContentValues();
		value.put(MERE_COLUMN1, this.getMere_profileid());
		value.put(MERE_COLUMN7, this.getMere_testid());
		value.put(MERE_COLUMN8, this.getMere_id());
		value.put(MERE_COLUMN2, this.getMere_name());
		value.put(MERE_COLUMN3, this.getMere_usage());
		value.put(MERE_COLUMN4, this.getMere_dosage());
		value.put(MERE_COLUMN5, this.getMere_time());
		value.put(MERE_COLUMN6, this.getMere_obedience());
		
		String where = MERE_COLUMN8 + "=" + _Id + " and "+MERE_COLUMN1 + "=" + profileId + " and "+MERE_COLUMN7 + "=" + testId + "";
		mContext.getContentResolver().update(CONTENT_URI_TB8, value, where, null);
	}
	
	/**
	 * 删除患者的某次吃药信息
	 * @param profileId 档案编号
	 * @param testId 体检表编号
	 * @param _Id 药品使用情况编号
	 */
	public void delectMedicateRecord(int profileId,int testId,int _Id){
		String where = MERE_COLUMN8 + "=" + _Id + " and "+MERE_COLUMN1 + "=" + profileId + " and "+MERE_COLUMN7 + "=" + testId + "";
		mContext.getContentResolver().delete(CONTENT_URI_TB8, where, null);
	}
	
	/**
	 * 删除患者的全部用药史记录
	 * @param profileId 档案编号
	 */
	public void delectMedicateRecord(int profileId){
		String where = MERE_COLUMN1 + "=" + profileId + "";
		mContext.getContentResolver().delete(CONTENT_URI_TB8, where, null);
	}
}
